﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.IO;

public partial class Secretaria_bol : System.Web.UI.Page
{
    static Zoom zm = new Zoom();
    Boolean bforceExecute = false;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HtmlInputText txtZoom = (HtmlInputText)Page.FindControl("zoom");
            txtZoom.Value = zm.GetZoomFromUsuario(biFactory.User().IdUsuario);
        }
       // Response.Write(HttpContext.Current.Request.Form["Message"].ToString());
        

    }
    protected override void Render(HtmlTextWriter writer)
    {
        //<html>
        writer.RenderBeginTag(HtmlTextWriterTag.Html);
        // <head>
        writer.RenderBeginTag(HtmlTextWriterTag.Head);
        // </head>
        writer.RenderEndTag();
        // <body>
        writer.RenderBeginTag(HtmlTextWriterTag.Body);

        RenderXSL(writer);

        // </body>
        writer.RenderEndTag();
        // </html>
        writer.RenderEndTag();

        base.Render(writer);

    }

    private void RenderXSL(HtmlTextWriter writer)
    {
        XmlDataAlumnos xdalumnos = new XmlDataAlumnos();
        XmlDocument osource;


        osource = (XmlDocument)Cache.Get("alumno" + Request.QueryString["idalumno"].ToString());

        if (osource == null || HttpContext.Current.Request.QueryString["cache"] != null)
        {
            osource = xdalumnos.getBoletin(int.Parse(Request.QueryString["idalumno"].ToString()));
            Cache.Add("alumno" + Request.QueryString["idalumno"].ToString(), osource, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);
        }


        System.IO.StringReader reader = new StringReader(osource.InnerXml);
        System.Xml.XPath.XPathDocument doc = new XPathDocument(reader);

        System.Xml.Xsl.XslTransform trans = new XslTransform();
        trans.Load(Server.MapPath("../Datatest/boletin.xsl"));
        //trans.Transform(doc, null, Response.OutputStream, new XmlUrlResolver());


        trans.Transform(doc, null, writer, new XmlUrlResolver());



    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        HtmlInputText txtZoom = (HtmlInputText)Page.FindControl("zoom");
        zm.Save(biFactory.User().IdUsuario, txtZoom.Value);
        txtZoom.Style["Color"] = "red";
        
    }
}
